package 链表;

import common.ListNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tmh
 * @date 2024/11/22 18:51
 * @description
 */
public class T234回文链表 {
    public boolean isPalindrome(ListNode head) {
        List<Integer> list = new ArrayList<>();
        while (head != null) {
            list.add(head.val);
            head = head.next;
        }
        for (int i = 0, j = list.size() - 1; i < j; i++, j--) {
            if (!list.get(i).equals(list.get(j))) {
                return false;
            }
        }
        return true;
    }

}
